




/*
'===============================================================================
'  MP.LayerHelper.MP_OBS.BL.MaAgentGroupManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using MP.LayerHelper.MP_OBS.BLL;
using MP.LayerHelper.MP_OBS.DAL;
using MP.LayerHelper.MP_OBS.DAL.EntityClasses;
using MP.LayerHelper.MP_OBS.DAL.FactoryClasses;
using MP.LayerHelper.MP_OBS.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MP.LayerHelper.MP_OBS.BLL
{
	public class MaAgentGroupManagerBase : ManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		
		public MaAgentGroupManagerBase()
		{
			// Nothing for now.
		}
		
		public override string TableName()
        {
            return "MaAgentGroup";
        }
		
		public MaAgentGroupEntity Insert(MaAgentGroupEntity _MaAgentGroupEntity)
		{
			return Insert(_MaAgentGroupEntity, "");
		}
		
		public MaAgentGroupEntity Insert(MaAgentGroupEntity _MaAgentGroupEntity, string controlId)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(_MaAgentGroupEntity, true);
				MaAgentGroupFields field = new MaAgentGroupFields();
                LogEntity(_MaAgentGroupEntity, field, AcInsert, controlId);
			}
			return _MaAgentGroupEntity;
		}

		
		public MaAgentGroupEntity Insert(Guid Id, string AgentGroupCode, string AgentGroupName, Guid BranchId, DateTime CreatedDate, string CreatedBy, string UpdatedBy, DateTime UpdatedDate, bool IsDeleted, Guid DepartmentId, int OrderIndex)
		{
			MaAgentGroupEntity _MaAgentGroupEntity = new MaAgentGroupEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_MaAgentGroupEntity.Id = Id;
				_MaAgentGroupEntity.AgentGroupCode = AgentGroupCode;
				_MaAgentGroupEntity.AgentGroupName = AgentGroupName;
				_MaAgentGroupEntity.BranchId = BranchId;
				_MaAgentGroupEntity.CreatedDate = CreatedDate;
				_MaAgentGroupEntity.CreatedBy = CreatedBy;
				_MaAgentGroupEntity.UpdatedBy = UpdatedBy;
				_MaAgentGroupEntity.UpdatedDate = UpdatedDate;
				_MaAgentGroupEntity.IsDeleted = IsDeleted;
				_MaAgentGroupEntity.DepartmentId = DepartmentId;
				_MaAgentGroupEntity.OrderIndex = OrderIndex;
				MaAgentGroupFields field = new MaAgentGroupFields();
                LogEntity(_MaAgentGroupEntity, field, AcInsert);
				adapter.SaveEntity(_MaAgentGroupEntity, true);
			}
			return _MaAgentGroupEntity;
		}

		public MaAgentGroupEntity Insert(string AgentGroupCode, string AgentGroupName, Guid BranchId, DateTime CreatedDate, string CreatedBy, string UpdatedBy, DateTime UpdatedDate, bool IsDeleted, Guid DepartmentId, int OrderIndex)
		{
			MaAgentGroupEntity _MaAgentGroupEntity = new MaAgentGroupEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_MaAgentGroupEntity.AgentGroupCode = AgentGroupCode;
				_MaAgentGroupEntity.AgentGroupName = AgentGroupName;
				_MaAgentGroupEntity.BranchId = BranchId;
				_MaAgentGroupEntity.CreatedDate = CreatedDate;
				_MaAgentGroupEntity.CreatedBy = CreatedBy;
				_MaAgentGroupEntity.UpdatedBy = UpdatedBy;
				_MaAgentGroupEntity.UpdatedDate = UpdatedDate;
				_MaAgentGroupEntity.IsDeleted = IsDeleted;
				_MaAgentGroupEntity.DepartmentId = DepartmentId;
				_MaAgentGroupEntity.OrderIndex = OrderIndex;
				adapter.SaveEntity(_MaAgentGroupEntity, true);
				MaAgentGroupFields field = new MaAgentGroupFields();
                LogEntity(_MaAgentGroupEntity, field, AcInsert);
			}
			return _MaAgentGroupEntity;
		}
		
		public bool Update(MaAgentGroupEntity _MaAgentGroupEntity)
        {
            return Update(_MaAgentGroupEntity, "");
        }

		public bool Update(MaAgentGroupEntity _MaAgentGroupEntity, string controlId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(MaAgentGroupFields.Id == _MaAgentGroupEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_MaAgentGroupEntity, filter);
				toReturn = true;
				
				MaAgentGroupFields field = new MaAgentGroupFields();
                LogEntity(_MaAgentGroupEntity, field, AcUpdate, controlId);
			}
			return toReturn;
		}
		
		public bool Update(MaAgentGroupEntity _MaAgentGroupEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_MaAgentGroupEntity, filter);
				toReturn = true;
				
				MaAgentGroupFields field = new MaAgentGroupFields();
                LogEntity(_MaAgentGroupEntity, field, AcUpdate);
			}
			return toReturn;
		}

		public bool Update(Guid Id, string AgentGroupCode, string AgentGroupName, Guid BranchId, DateTime CreatedDate, string CreatedBy, string UpdatedBy, DateTime UpdatedDate, bool IsDeleted, Guid DepartmentId, int OrderIndex)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MaAgentGroupEntity _MaAgentGroupEntity = new MaAgentGroupEntity(Id);
				if (adapter.FetchEntity(_MaAgentGroupEntity))
				{
				
					_MaAgentGroupEntity.AgentGroupCode = AgentGroupCode;
					_MaAgentGroupEntity.AgentGroupName = AgentGroupName;
					_MaAgentGroupEntity.BranchId = BranchId;
					_MaAgentGroupEntity.CreatedDate = CreatedDate;
					_MaAgentGroupEntity.CreatedBy = CreatedBy;
					_MaAgentGroupEntity.UpdatedBy = UpdatedBy;
					_MaAgentGroupEntity.UpdatedDate = UpdatedDate;
					_MaAgentGroupEntity.IsDeleted = IsDeleted;
					_MaAgentGroupEntity.DepartmentId = DepartmentId;
					_MaAgentGroupEntity.OrderIndex = OrderIndex;
					adapter.SaveEntity(_MaAgentGroupEntity, true);
					toReturn = true;
					
					MaAgentGroupFields field = new MaAgentGroupFields();
					LogEntity(_MaAgentGroupEntity, field, AcUpdate);
				}
			}
			return toReturn;
		}

		public bool Delete(Guid Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MaAgentGroupEntity _MaAgentGroupEntity = new MaAgentGroupEntity(Id);
				if (adapter.FetchEntity(_MaAgentGroupEntity))
				{
					adapter.DeleteEntity(_MaAgentGroupEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", null);
			}
		}
		
		
		public int DeleteById(Guid Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByAgentGroupCode(string AgentGroupCode)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupCode == AgentGroupCode);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByAgentGroupName(string AgentGroupName)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupName == AgentGroupName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByBranchId(Guid BranchId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.BranchId == BranchId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByCreatedDate(DateTime CreatedDate)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedDate == CreatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByCreatedBy(string CreatedBy)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedBy == CreatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByUpdatedBy(string UpdatedBy)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedBy == UpdatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByUpdatedDate(DateTime UpdatedDate)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedDate == UpdatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByIsDeleted(bool IsDeleted)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.IsDeleted == IsDeleted);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByDepartmentId(Guid DepartmentId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.DepartmentId == DepartmentId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByOrderIndex(int OrderIndex)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.OrderIndex == OrderIndex);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MaAgentGroupEntity", filter);
			}
			return toReturn;
		}
		

		
		public MaAgentGroupEntity SelectOne(Guid Id)
		{
			MaAgentGroupEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MaAgentGroupEntity _MaAgentGroupEntity = new MaAgentGroupEntity(Id);
				if (adapter.FetchEntity(_MaAgentGroupEntity))
				{
					toReturn = _MaAgentGroupEntity;
				}
			}
			return toReturn;
		}

		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectAllLST()
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, null, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectAllLST_Paged(int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, null, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByIdLST(Guid Id)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByIdLST_Paged(Guid Id, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(Guid Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT_Paged(Guid Id, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByAgentGroupCodeLST(string AgentGroupCode)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupCode == AgentGroupCode);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByAgentGroupCodeLST_Paged(string AgentGroupCode, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupCode == AgentGroupCode);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByAgentGroupCodeRDT(string AgentGroupCode)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupCode == AgentGroupCode);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByAgentGroupCodeRDT_Paged(string AgentGroupCode, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupCode == AgentGroupCode);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByAgentGroupNameLST(string AgentGroupName)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupName == AgentGroupName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByAgentGroupNameLST_Paged(string AgentGroupName, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupName == AgentGroupName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByAgentGroupNameRDT(string AgentGroupName)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupName == AgentGroupName);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByAgentGroupNameRDT_Paged(string AgentGroupName, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.AgentGroupName == AgentGroupName);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByBranchIdLST(Guid BranchId)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.BranchId == BranchId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByBranchIdLST_Paged(Guid BranchId, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.BranchId == BranchId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByBranchIdRDT(Guid BranchId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.BranchId == BranchId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByBranchIdRDT_Paged(Guid BranchId, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.BranchId == BranchId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByCreatedDateLST(DateTime CreatedDate)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedDate == CreatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByCreatedDateLST_Paged(DateTime CreatedDate, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedDate == CreatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCreatedDateRDT(DateTime CreatedDate)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedDate == CreatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByCreatedDateRDT_Paged(DateTime CreatedDate, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedDate == CreatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByCreatedByLST(string CreatedBy)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedBy == CreatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByCreatedByLST_Paged(string CreatedBy, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedBy == CreatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCreatedByRDT(string CreatedBy)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedBy == CreatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByCreatedByRDT_Paged(string CreatedBy, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.CreatedBy == CreatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByUpdatedByLST(string UpdatedBy)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedBy == UpdatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByUpdatedByLST_Paged(string UpdatedBy, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedBy == UpdatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByUpdatedByRDT(string UpdatedBy)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedBy == UpdatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByUpdatedByRDT_Paged(string UpdatedBy, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedBy == UpdatedBy);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByUpdatedDateLST(DateTime UpdatedDate)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedDate == UpdatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByUpdatedDateLST_Paged(DateTime UpdatedDate, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedDate == UpdatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByUpdatedDateRDT(DateTime UpdatedDate)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedDate == UpdatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByUpdatedDateRDT_Paged(DateTime UpdatedDate, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.UpdatedDate == UpdatedDate);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByIsDeletedLST(bool IsDeleted)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.IsDeleted == IsDeleted);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByIsDeletedLST_Paged(bool IsDeleted, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.IsDeleted == IsDeleted);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIsDeletedRDT(bool IsDeleted)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.IsDeleted == IsDeleted);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByIsDeletedRDT_Paged(bool IsDeleted, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.IsDeleted == IsDeleted);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByDepartmentIdLST(Guid DepartmentId)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.DepartmentId == DepartmentId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByDepartmentIdLST_Paged(Guid DepartmentId, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.DepartmentId == DepartmentId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByDepartmentIdRDT(Guid DepartmentId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.DepartmentId == DepartmentId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByDepartmentIdRDT_Paged(Guid DepartmentId, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.DepartmentId == DepartmentId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByOrderIndexLST(int OrderIndex)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.OrderIndex == OrderIndex);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return EntityCollection<MaAgentGroupEntity>
		public EntityCollection<MaAgentGroupEntity> SelectByOrderIndexLST_Paged(int OrderIndex, int PageNumber, int PageSize)
		{
			EntityCollection<MaAgentGroupEntity> _MaAgentGroupCollection = new EntityCollection<MaAgentGroupEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.OrderIndex == OrderIndex);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MaAgentGroupCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MaAgentGroupCollection;
		}
		
		// Return DataTable
		public DataTable SelectByOrderIndexRDT(int OrderIndex)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.OrderIndex == OrderIndex);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByOrderIndexRDT_Paged(int OrderIndex, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MaAgentGroupCollection = new EntityCollection(new MaAgentGroupEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MaAgentGroupFields.OrderIndex == OrderIndex);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MaAgentGroupCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		

	}
}
